using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using ViCode_LeVi.Controls.Logs;

namespace ViCode_LeVi.Controls.Reports
{
    public partial class QuestionAnswerSubReport : DevExpress.XtraReports.UI.XtraReport
    {
        private int m_iPart;
        private int m_iStep;
    
        public QuestionAnswerSubReport()
        {
            this.InitializeComponent();
        }

        private bool CreateDataBindings()
        {
            bool flag = true;
            try
            {
                //this.cellQuestion.DataBindings.Add("Text", base.DataSource, "Question");
                //this.cellAnswer.DataBindings.Add("Text", base.DataSource, "Answer");
                
                this.cellQuestion.DataBindings.Add("Rtf", base.DataSource, "Question");
                this.cellAnswer.DataBindings.Add("Rtf", base.DataSource, "Answer");
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in QuestionAnswerSubReport.CreateDataBindings: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        public bool CreateReport(int iStep, int iPart, ref bool bQuestionsAndAnswers)
        {
            bool flag = true;
            try
            {
                this.Step = iStep;
                this.Part = iPart;
                var data =new ReportDataSourceHelper().GetReportQuestionAnswerList(this.Step, this.Part);
                base.DataSource = data;
                if (data.Length > 0)
                {
                    bQuestionsAndAnswers = true;
                    return this.CreateDataBindings();
                }
                bQuestionsAndAnswers = false;
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in QuestionAnswerSubReport.CreateReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }             

        public int Part
        {
            get
            {
                return this.m_iPart;
            }
            set
            {
                this.m_iPart = value;
            }
        }

        public int Step
        {
            get
            {
                return this.m_iStep;
            }
            set
            {
                this.m_iStep = value;
            }
        }
    }
}
